package com.woniu.apartment.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShaoxUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.woniu.apartment.domain.Wish;
import com.woniu.apartment.service.IWishService;
import io.netty.util.internal.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户收藏房型和公寓列Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbwish")
@Api("用户收藏房型和公寓列管理")
public class WishWebController extends BaseController
{
    @Autowired
    private IWishService wishService;

    /**
     * 查询用户收藏房型和公寓列列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbwish:list')")
    @GetMapping("web/likeById")
    @ApiOperation("用户收藏房型和公寓列分页查询")
    public AjaxResult likeById(Long apartmentId)
    {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String uid = request.getHeader("userId");
        Long userId = Long.valueOf(uid);
        Wish wish = wishService.likeById(apartmentId,userId);
        if (wish==null){
            return AjaxResult.success(0);
        }
        return AjaxResult.success(1);

    }

    @GetMapping("web/changeWish")
    @ApiOperation("用户收藏房型和公寓列分页查询")
    public AjaxResult changeWish(Long apartmentId)
    {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String uid = request.getHeader("userId");
        Long userId = Long.valueOf(uid);
        int i = wishService.changeWish(apartmentId, userId);
        return AjaxResult.success(i);

    }



}
